// pages/feedback/feedback.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabs:[
            {
                id:0,
                value:'体验问题',
                isActive:true,
            },{
                id:1,
                value:'商品、商家投诉',
                isActive:false,
            }
        ],
        chooseImg:[],
        textVal:''
    },
    /* 切换tab栏 */
    handletabsItemChange(e){
        /* 获取被点击的标题索引 */
        const {index} = e.detail
        const {tabs} = this.data
        /* 修改原数组 */
        tabs.forEach((v,i) => {i===index?v.isActive=true:v.isActive=false});
        /* 赋值到data中 */
        this.setData({
            tabs
        })
    },
    /* 点击选择图片 */
    handleChooseImg(){
        /* 调用小程序内部选图片api */
        wx.chooseImage({
            count: 9,
            sizeType: ['original','compressed'],
            sourceType: ['album','camera'],
            success: (result)=>{
                this.setData({
                    chooseImg:[...this.data.chooseImg,...result.tempFilePaths]
                })
            }
        });
    },
    /* 移除图片 */
    handleRemoveImg(e){
        const {index} = e.currentTarget.dataset
        console.log(index);
        let {chooseImg} = this.data
        chooseImg.splice(index,1)
        this.setData({
            chooseImg
        })
    },
    /* 文本域输入事件 */
    handleTextInput(e){
        this.setData({
            textVal:e.detail.value
        })
    },
    handleFormSub(){
        const value = this.data.textVal
        if (!value.trim()) {
            wx.showToast({
                title: '输入不合法',
                icon: 'none'
            });
            return
        }
        /* var upTask = wx.uploadFile({
            url: '',
            filePath: ,
            name: ,
            formData: {}
        }); */
    }
})